﻿using SL651Center2.x.Enums;
using System.Text;

namespace SL651Center2.x.Config
{
    /// <summary>
    /// 中心站配置
    /// </summary>
    public class CentralConfig
    {
        /// <summary>
        /// 帧编码格式
        /// </summary>
        public FrameCode FrameCode { get; set; } = FrameCode.HEX＿BCD;
        /// <summary>
        /// 中心站地址(十六进制字符串)
        /// </summary>
        public string CentralAddress { get; set; } = string.Empty;
        /// <summary>
        /// 密码(十六进制字符串)
        /// </summary>
        public string PassWord { get; set; } = string.Empty;

        public TelemetryInfo GetTelemetryInfo(string TelemetryAddress)
        {
            TelemetryInfo telemetryInfo = new TelemetryInfo();
            telemetryInfo.FrameCode = FrameCode;
            if (FrameCode == FrameCode.ASCII)
            {
                var tb = Encoding.ASCII.GetBytes(TelemetryAddress);
                telemetryInfo.TelemetryAddress = tb;
                var cb = Encoding.ASCII.GetBytes(CentralAddress);
                telemetryInfo.CentralAddress = cb;
                var pb = Encoding.ASCII.GetBytes(PassWord);
                telemetryInfo.PassWord = pb;
            }
            else
            {
                var tb = Helper.HEXStrToByte(TelemetryAddress);
                telemetryInfo.TelemetryAddress = tb;
                var cb = Helper.HEXStrToByte(CentralAddress);
                telemetryInfo.CentralAddress = cb;
                var pb = Helper.HEXStrToByte(PassWord);
                telemetryInfo.PassWord = pb;
            }
            return telemetryInfo;

        }

    }
}
